//
//  EIMSAppDelegate.m
//  SP2P_7
//
//  Created by EIMS. on 14-6-6.
//  Copyright (c) 2014年 EIMS. All rights reserved.
//

#import "AppDelegate.h"
#import "OpenGestureLockViewController.h"
#import "GuideViewController.h"
#import "BPush.h"
#import "JSONKit.h"
#import <ShareSDK/ShareSDK.h>
//腾讯SDK头文件
#import <TencentOpenAPI/TencentOAuth.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <QQConnection/QQConnection.h>
//新浪微博SDK头文件
#import "WeiboSDK.h"
//微信SDK头文件
#import "WXApi.h"
#import "REFrostedViewController.h"
#import "TabViewController.h"
// 判断iPhone型号
#import "IsiPhoneDevice.h"
#import "GesDatabase.h"
#define SUPPORT_IOS8 1   //是否在IOS8设备运行
@interface AppDelegate ()<UIAlertViewDelegate, HTTPClientDelegate>

@property (copy, nonatomic  ) NSString      *idNum;
@property (copy, nonatomic  ) NSString      *billidNum;
@property (copy, nonatomic  ) NSString      *bidNum;
@property (copy, nonatomic  ) NSString      *typeStr;
@property (nonatomic, strong) UIView        *viewContent;
@property (nonatomic, strong) UIImageView   *adImageView;
@property (nonatomic, strong) NetWorkClient *requestClient;
@property (nonatomic, strong) NetWorkClient *loginRequestClient;
@property (nonatomic, assign) NSInteger requestType;
@end

@implementation AppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    [ShareSDK registerApp:@"41721a1de002"];     //参数为ShareSDK官网中添加应用后得到的AppKey
    
    //添加微信应用 注册网址 http://open.weixin.qq.com//
    [ShareSDK connectWeChatWithAppId:@"wx487dcc3940d3092a"//wx12be9e3d2b80b0b4
                           appSecret:@"910148a981b04a44c031a3d47929b2e7"
                           wechatCls:[WXApi class]];
    
    //添加新浪微博应用 注册网址 http://open.weibo.com
    [ShareSDK connectSinaWeiboWithAppKey:@"568898243"
                               appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"
                             redirectUri:@"http://www.sharesdk.cn"];
    
    
    //添加QQ空间应用  注册网址  http://connect.qq.com/intro/login/
    [ShareSDK connectQZoneWithAppKey:@"1103427727"
                           appSecret:@"NlovF77litfDDiUd"
                   qqApiInterfaceCls:[QQApiInterface class]
                     tencentOAuthCls:[TencentOAuth class]];
    
    //添加QQ应用  注册网址  http://open.qq.com/
    [ShareSDK connectQQWithQZoneAppKey:@"1103432166"
                     qqApiInterfaceCls:[QQApiInterface class]
                       tencentOAuthCls:[TencentOAuth class]];
    
    
    //连接邮件
    [ShareSDK connectMail];
    
    //连接短信分享
    [ShareSDK connectSMS];
    
    
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.rootViewController = [[UIViewController alloc] init];
    [self.window makeKeyAndVisible];
    
    [self startAdView];
    NSLog(@"22222");
    [self performSelector:@selector(startAnim) withObject:nil afterDelay:1.5f];
    
/*    //百度云推送
#if SUPPORT_IOS8
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        UIUserNotificationType myTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
        
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:myTypes categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    }else
#endif
    {
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
    }
    
    
#warning 上线 AppStore 时需要修改BPushMode为BPushModeProduction 需要修改Apikey为自己的Apikey
    
    // 在 App 启动时注册百度云推送服务，需要提供 Apikey
    [BPush registerChannel:launchOptions apiKey:@"0RKGUFPs6ZAfzumlvcIkuRuP" pushMode:BPushModeProduction withFirstAction:nil withSecondAction:nil withCategory:nil isDebug:YES];
    
    
    
    if (launchOptions != nil) {
        DLOG(@"LUN:%@", launchOptions);
        
        NSDictionary *userInfo = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
        DLOG(@"推送内容为:%@",userInfo);
        
        [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
        
        if ([userInfo objectForKey:@"id"] != nil &&![[userInfo objectForKey:@"id"] isEqual:[NSNull null]]) {
            
            NSString *idStr = [userInfo objectForKey:@"id"];
            
            InfoNewsViewController *infoView = [[InfoNewsViewController alloc] init];
            UINavigationController *infoNv = [[UINavigationController alloc] initWithRootViewController:infoView];
            infoView.newsId = [NSString stringWithFormat:@"%@",idStr];
            infoView.typeStr = @"推送";
            [self.window.rootViewController presentViewController:infoNv animated:YES completion:nil];
            
        }
    }*/
    
    [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                           [UIColor whiteColor], NSForegroundColorAttributeName,
                                                           [UIFont fontWithName:@"Arial-BoldMT" size:18.0], NSFontAttributeName, nil]];
    
    return YES;
}

-(void) startAdView
{
    //设置动画效果
    _viewContent = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height)];// 广告界面，可以为webview等
    _viewContent.backgroundColor = [UIColor clearColor];
    UIImageView *bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height)];
    // 加一张遮盖底图，防止闪屏，空白跳转
    DLOG(@"设备型号: %@", [IsiPhoneDevice deviceString]);
    //  NSString *deviceString = [IsiPhoneDevice deviceString];
    
    if (IS_iPhone5) {
        
        bg.image = [UIImage imageNamed:@"LaunchImage-700-568h"];
        
    }else if(IS_iPhone4) {
        
        bg.image = [UIImage imageNamed:@"LaunchImage-700"];
        
    }else if(IS_iPhone6) {
        
        bg.image = [UIImage imageNamed:@"LaunchImage-800-667h"];
        
    }else if(IS_iPhone6plus) {
        
        bg.image = [UIImage imageNamed:@"LaunchImage-800-Portrait-736h"];
    }
    
    [_viewContent addSubview:bg];
    
    _adImageView =[[UIImageView alloc] init];
    _adImageView.frame = CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height);
    
    //将图片添加到UIImageView对象中
    _adImageView.backgroundColor = [UIColor clearColor];
    // 加载上一次缓存的广告图
    [_adImageView sd_setImageWithURL:[NSURL URLWithString:[[AppDefaultUtil sharedInstance] getAppImage]]];
    
    
    [_viewContent addSubview:_adImageView];
    
    [self.window addSubview:_viewContent];
    
    //    [self.window bringSubviewToFront:_viewContent];
    
    // 请求网络图片，延时0.2s，避免 AFNetworkReachabilityManager未准备就绪的Bug
    [self performSelector:@selector(requestData) withObject:nil afterDelay:0.2f];
}

-(void) startAnim
{
    [UIView animateWithDuration:0.0 animations:^{
        _viewContent.alpha = 0;
    } completion:^(BOOL finished) {
        
    }];
   
    
    [self startRootView];
}

- (void)startRootView
{
    
    if(![[AppDefaultUtil sharedInstance] isFirstLancher])
    {
        // 第一次启动，直接启动引导界面
        [[AppDefaultUtil sharedInstance] setFirstLancher:YES];
        [[AppDefaultUtil sharedInstance] setRemeberUser:YES];
        
        [AppDelegateInstance setOpenType:@"1"];
        
        //启动引导页
        GuideViewController *guideView = [[GuideViewController alloc]  init];
        self.window.rootViewController = guideView;
        [self.window makeKeyAndVisible];
        
    } else {
        NSString *account=[[AppDefaultUtil sharedInstance]getDefaultAccount];
        NSString *gestureState=[[GesDatabase getInstance] getGestureState:account];
        //DLOG(@"gestureState-->%@-->%@",account,gestureState);
        //判断最后一次登录的账户是否设置手势密码
        if([gestureState isEqualToString:@"1"]) {
            //手势密码登录界面
            OpenGestureLockViewController *openGestureLockView = [[OpenGestureLockViewController alloc] init];
            openGestureLockView.type = LaunchingEnter;
            self.window.rootViewController = openGestureLockView;
            [self.window makeKeyAndVisible];

        }else {
            NSString *name = [[AppDefaultUtil sharedInstance] getDefaultAccount];
            NSString *password = [[AppDefaultUtil sharedInstance] getDefaultUserPassword];
            if (name && password) {
                [self login];
            }else {
               
                [self goMainView];
           
            }
        }
    }
}

- (void)goMainView {
    //没有则进入主界面
    TabViewController *tabViewController = [TabViewController shareTableView];
    self.window.rootViewController = tabViewController;
    [self.window makeKeyAndVisible];
    
    
}

- (void)login
{
    _requestType = 2;
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    NSString *name = [[AppDefaultUtil sharedInstance] getDefaultAccount];
    NSString *password = [[AppDefaultUtil sharedInstance] getDefaultUserPassword];
    // NSString *deviceType = [[AppDefaultUtil sharedInstance] getdeviceType];
    [parameters setObject:@"1" forKey:@"OPT"];
    [parameters setObject:@"" forKey:@"body"];
    [parameters setObject:name forKey:@"name"];
    [parameters setObject:password forKey:@"pwd"];
    if(AppDelegateInstance.userId !=nil && AppDelegateInstance.channelId != nil) {
        [parameters setObject:AppDelegateInstance.userId forKey:@"userId"];
        [parameters setObject:AppDelegateInstance.channelId forKey:@"channelId"];
    }else {
        [parameters setObject:@"" forKey:@"userId"];
        [parameters setObject:@"" forKey:@"channelId"];
    }
    [parameters setObject:@"2" forKey:@"deviceType"];
    if (_loginRequestClient == nil) {
        _loginRequestClient = [[NetWorkClient alloc] init];
        _loginRequestClient.delegate = self;
        [self goMainView];
    }
    
    [_loginRequestClient requestGet:@"app/services" withParameters:parameters];
   
    
}


- (BOOL)application:(UIApplication *)application  handleOpenURL:(NSURL *)url
{
    return [ShareSDK handleOpenURL:url
                        wxDelegate:self];
}

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return [ShareSDK handleOpenURL:url
                 sourceApplication:sourceApplication
                        annotation:annotation
                        wxDelegate:self];
}

#if SUPPORT_IOS8
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    //register to receive notifications
    [application registerForRemoteNotifications];
}
#endif

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults removeObjectForKey:@"deviceToken"];
    [userDefaults setObject:deviceToken forKey:@"deviceToken"];
    //DLOG(@"My token is: %@", [userDefaults objectForKey:@"deviceToken"]);
    //注册 Device Token
    [BPush registerDeviceToken:[userDefaults objectForKey:@"deviceToken"]];
    //绑定
    [BPush bindChannelWithCompleteHandler:^(id result, NSError *error) {
        if (result) {
            [BPush setTag:@"P2P" withCompleteHandler:^(id result, NSError *error) {
                if (result) {
                    //DLOG(@"设置tag成功");
                }
            }];
        }
    }];;
    //    NSString *str2 = [@"dfdkjfkd is " stringByAppendingFormat: @"Register device token: %@\n openudid: %@", deviceToken, [OpenUDID value]];
    //    DLOG(@"str2 str2 str2 is %@",str2);
    //DLOG(@"deviceToken is %@",deviceToken);
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    
    //DLOG(@"注册设备时的错误为:%@",error);
    
    
}


//返回绑定等调用的结果
- (void) onMethod:(NSString*)method response:(NSDictionary*)data {
    //DLOG(@"On method:%@", method);
    //DLOG(@"data:%@", [data description]);
    NSDictionary* res = [[NSDictionary alloc] initWithDictionary:data];
    if ([BPushRequestMethodBind isEqualToString:method]) {
        NSString *appid = [res valueForKey:BPushRequestAppIdKey];
        NSString *userid = [res valueForKey:BPushRequestUserIdKey];
        NSString *channelid = [res valueForKey:BPushRequestChannelIdKey];
        NSString *requestid = [res valueForKey:BPushRequestRequestIdKey];
        int returnCode = [[res valueForKey:BPushRequestErrorCodeKey] intValue];
        
        if (returnCode == 0) {
            //DLOG(@"appid is %@ userid is %@ channelid is %@ requestid is %@",appid,userid,channelid,requestid);
            
            // 在内存中备份，以便短时间内进入可以看到这些值，而不需要重新bind
            self.appId = appid;
            self.channelId = channelid;
            self.userId = userid;
            //DLOG(@"app id is %@,channelId is %@,userId is %@",appid,channelid,userid);
            
        }
    } else if ([BPushRequestMethodUnbind isEqualToString:method]) {
        int returnCode = [[res valueForKey:BPushRequestErrorCodeKey] intValue];
        if (returnCode == 0) {
            //            self.viewController.appidText.text = nil;
            //            self.viewController.useridText.text = nil;
            //            self.viewController.channelidText.text = nil;
        }
    }
    NSString *str = [[NSString alloc] initWithFormat: @"%@ return: \n%@", method, [data description]];
    DLOG(@"返回的数据是 %@",str);
    
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    
   /* DLOG(@"Receive Notify: %@", [userInfo JSONString]);
    if ([userInfo objectForKey:@"id"] != nil &&![[userInfo objectForKey:@"id"] isEqual:[NSNull null]] && [userInfo objectForKey:@"billId"] != nil &&![[userInfo objectForKey:@"billId"] isEqual:[NSNull null]] && [userInfo objectForKey:@"bidId"] != nil && ![[userInfo objectForKey:@"bidId"] isEqual:[NSNull null]]) {
        
        NSString *idStr = [userInfo objectForKey:@"id"];
        NSString *billIdStr = [userInfo objectForKey:@"billId"];
        NSString *bidIdStr = [userInfo objectForKey:@"bidId"];
        _typeStr = [userInfo objectForKey:@"type"];
        NSString *titleStr = [userInfo objectForKey:@"title"];
        NSString *descriptionStr = [userInfo objectForKey:@"description"];
        NSString *badgenum = [[userInfo objectForKey:@"aps"] objectForKey:@"badge"];
        if([badgenum integerValue])
        {
            [application setApplicationIconBadgeNumber:[badgenum integerValue]];
        }
        
        if (![[UIApplication sharedApplication].keyWindow isKindOfClass:[GestureLockViewController class]]&& ![[UIApplication sharedApplication].keyWindow isKindOfClass:[OpenLockViewController class]]) {
            
            //活动类型
            if ([_typeStr isEqualToString:@"1"]) {
                
                _idNum = idStr;
                if (application.applicationState == UIApplicationStateActive) {
                    // Nothing to do if applicationState is Inactive, the iOS already displayed an alert view.
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:titleStr
                                                                        message:descriptionStr
                                                                       delegate:self
                                                              cancelButtonTitle:@"取消"
                                                              otherButtonTitles:@"确定",nil];
                    [alertView show];
                }else{
                    
                    InfoNewsViewController *infoView = [[InfoNewsViewController alloc] init];
                    UINavigationController *infoNv = [[UINavigationController alloc] initWithRootViewController:infoView];
                    infoView.newsId = [NSString stringWithFormat:@"%@",_idNum];
                    infoView.typeStr = @"推送";
                    [self.window.rootViewController presentViewController:infoNv animated:YES completion:nil];
                    
                }
                
            }
            //账单类型
            if ([_typeStr isEqualToString:@"2"]) {
                
                _billidNum = billIdStr;
                if (application.applicationState == UIApplicationStateActive)
                {
                    // Nothing to do if applicationState is Inactive, the iOS already displayed an alert view.
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:titleStr
                                                                        message:descriptionStr
                                                                       delegate:self
                                                              cancelButtonTitle:@"取消"
                                                              otherButtonTitles:@"确定",nil];
                    [alertView show];
                }else{
                    
                    BillingDetailsViewController *billView = [[BillingDetailsViewController alloc] init];
                    UINavigationController *billNav = [[UINavigationController alloc] initWithRootViewController:billView];
                    billView.billId = [NSString stringWithFormat:@"%@",_billidNum];
                    billView.isPay = NO;
                    billView.typeStr = @"推送";
                    [self.window.rootViewController presentViewController:billNav animated:YES completion:nil];
                    
                }
            }
            
            //账单类型
            if ([_typeStr isEqualToString:@"3"]) {
                
                _bidNum = bidIdStr;
                if (application.applicationState == UIApplicationStateActive)
                {
                    // Nothing to do if applicationState is Inactive, the iOS already displayed an alert view.
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:titleStr
                                                                        message:descriptionStr
                                                                       delegate:self
                                                              cancelButtonTitle:@"取消"
                                                              otherButtonTitles:@"确定",nil];
                    [alertView show];
                }else{
                    
                    BorrowingDetailsViewController *borrowingDetailsView = [[BorrowingDetailsViewController alloc] init];
                    UINavigationController *bidNav = [[UINavigationController alloc] initWithRootViewController:borrowingDetailsView];
                    borrowingDetailsView.borrowID = [NSString stringWithFormat:@"%@", _bidNum];
                    borrowingDetailsView.typeStr = @"推送";
                    borrowingDetailsView.stateNum = 0;
                    [self.window.rootViewController presentViewController:bidNav animated:YES completion:nil];
                    
                }
            }
            
        }
        
        [application setApplicationIconBadgeNumber:0];
        [BPush handleNotification:userInfo];
    }
    */
}



#pragma mark UIalertViewdelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
  /*  if (buttonIndex!=0) {
        if ([_typeStr isEqualToString:@"1"]) {
            InfoNewsViewController *infoView = [[InfoNewsViewController alloc] init];
            UINavigationController *infoNv = [[UINavigationController alloc] initWithRootViewController:infoView];
            infoView.newsId = [NSString stringWithFormat:@"%@",_idNum];
            infoView.typeStr = @"推送";
            [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:infoNv animated:YES completion:nil];
            
        }else if ([_typeStr isEqualToString:@"2"]){
            
            BillingDetailsViewController *billView = [[BillingDetailsViewController alloc] init];
            UINavigationController *billNav = [[UINavigationController alloc] initWithRootViewController:billView];
            billView.billId = [NSString stringWithFormat:@"%@",_billidNum];
            billView.isPay = NO;
            billView.typeStr = @"推送";
            [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:billNav animated:YES completion:nil];
            
        }else{
            
            BorrowingDetailsViewController *borrowingDetailsView = [[BorrowingDetailsViewController alloc] init];
            UINavigationController *bidNav = [[UINavigationController alloc] initWithRootViewController:borrowingDetailsView];
            borrowingDetailsView.borrowID = [NSString stringWithFormat:@"%@", _bidNum];
            borrowingDetailsView.stateNum = 0;
            borrowingDetailsView.typeStr = @"推送";
            [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:bidNav animated:YES completion:nil];
            
        }
    }
    */
}


- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    //获取 appid
    self.appId = [BPush getAppId];
    self.userId = [BPush getUserId];
    self.channelId = [BPush getChannelId];
    
    //DLOG(@"相关ID2 是app  %@  user %@  channel %@",[BPush getAppId], [BPush getUserId],[BPush getChannelId]);
    
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    
    // 用户退出活动状态时，添加手势界面。
    //[self gotoGestureLockView];
}

- (void)gotoGestureLockView {
    
    NSString *account=[[AppDefaultUtil sharedInstance]getDefaultAccount];
    NSString *gestureState=[[GesDatabase getInstance] getGestureState:account];
    //DLOG(@"gestureState-->%@-->%@",account,gestureState);
    //判断最后一次登录的账户是否设置手势密码,有则需要开启
    if([gestureState isEqualToString:@"1"]) {
        if (![self.window.rootViewController isKindOfClass:[OpenGestureLockViewController class]]) {
            //_isLock = YES;
            //手势密码登录界面
            OpenGestureLockViewController *gestureLockView = [[OpenGestureLockViewController alloc] init];
            UINavigationController *gestureNav = [[UINavigationController alloc]initWithRootViewController:gestureLockView];
            gestureLockView.type = BackgroundEnter;
            [self.window.rootViewController presentViewController:gestureNav animated:NO completion:nil];
        }
    }else {
        // 其他情况直接算未登陆，直接跳转到主界面
    }
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}


- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

#pragma mark Request 网络请求数据
#pragma 获取网络启动图片
- (void)requestData
{
    _requestType = 1;
    DLOG(@"获取网络图片");
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    // 获取网络启动图片（opt = 161）
    [parameters setObject:@"161" forKey:@"OPT"];
    [parameters setObject:@"" forKey:@"body"];
    
    if (_requestClient == nil) {
        _requestClient = [[NetWorkClient alloc] init];
        _requestClient.delegate = self;
        
    }
    [_requestClient requestGet:@"app/services" withParameters:parameters];
    
}


#pragma mark HTTPClientDelegate 网络数据回调代理
-(void) startRequest
{
    
    //DLOG(@"****************************1");
}
// 返回成功
-(void) httpResponseSuccess:(NetWorkClient *)client dataTask:(NSURLSessionDataTask *)task didSuccessWithObject:(id)obj
{
    
    //DLOG(@"****************************2 dics -> %@", obj);
    
    NSDictionary *dics = obj;
    if (client == _requestClient) {
        if (dics.count == 0) {
            return;
        }
        
        if ([[NSString stringWithFormat:@"%@",[dics objectForKey:@"error"]] isEqualToString:@"-1"]) {
            
            if (![[dics objectForKey:@"fileNames"] isEqual:[NSNull null]]&& [dics objectForKey:@"fileNames"]!= nil) {
                
                NSArray *fileNames = [dics objectForKey:@"fileNames"];
                
                if (fileNames.count == 0) {
                    return;
                }
                
                NSString *imageUrl;
                
                if ([fileNames[0] hasPrefix:@"http"]) {
                    
                    imageUrl = [NSString stringWithFormat:@"%@", fileNames[0]];
                    
                }else{
                    imageUrl = [NSString stringWithFormat:@"%@%@", Baseurl, fileNames[0]];
                }
                
                //DLOG(@"imageUrl -> %@", imageUrl);
                
                [[AppDefaultUtil sharedInstance] setAppImage:imageUrl];
                
                [_adImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
            }
            
        }else {
            
            //DLOG(@"返回失败===========%@",[obj objectForKey:@"msg"]);
            
            [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@", [obj objectForKey:@"msg"]]];
            
        }
    }else if (client == _loginRequestClient) {
        
        if ([[NSString stringWithFormat:@"%@",[dics objectForKey:@"error"]] isEqualToString:@"-1"]) {
            
            //处理登录数据
            [CommonClass loginSuccessWithDictionary:dics];
            
            // 通知全局广播 LeftMenuController 修改UI操作
            [[NSNotificationCenter defaultCenter] postNotificationName:@"update" object:[obj objectForKey:@"username"]];
            
            //[self loginSuccess];// 登录成功
            
        }else {
            
        
        }
        
      //[self goMainView];
    }
    
}

// 返回失败
-(void) httpResponseFailure:(NetWorkClient *)client dataTask:(NSURLSessionDataTask *)task didFailWithError:(NSError *)error
{
    if (client == _loginRequestClient) {
        [self goMainView];
    }
}

// 无可用的网络
-(void) networkError
{
    //DLOG(@"****************************4");
    
    if (_requestType == 2) {
        [self goMainView];
    }
}


@end
